import json

import requests


def main():
    address = '北京市海淀区上地十街10号'
    url = f"https://api.map.baidu.com/geocoding/v3/?address={address}&output=json&ak=t1jnjFCB9RHoF9nHEQmToDaVrCzSxV9A&callback=showLocation"
    response = requests.get(url)
    content = str(response.content, 'utf-8')
    data = json.loads(content.replace('showLocation&&showLocation(', '').replace(')', ''))

    if data['status'] == 0:
        latitude = data['result']['location']['lat']
        longitude = data['result']['location']['lng']
        print(f"Latitude: {latitude}, Longitude: {longitude}")
    else:
        print("Error in API call")


if __name__ == '__main__':
    main()
